<?php
/**
 * Created by PhpStorm.
 * User: JSQ-SL
 * Date: 2018/10/19
 * Time: 16:16
 */

namespace app\index\table;

use app\index\controller\Login;
use app\index\service\ExcelService;
use think\Db;

class ArchiveLogTable extends BaseTable
{
    protected static $table = 'ARCHIVE_LOG';
    protected static $view = 'V_ARCHIVE_LOG';
    protected static $pk = 'LOG_ID';

    static public function table(){
        return Db::table(static::$view);
    }

    static public function add($data){
        $data['LOG_ID'] = self::getNextId();
        $data['USER_ID'] = Login::getUserId();
        $data['CREATE_TIME'] = date('Y-m-d H:i:s');
        self::toDate($data,'CREATE_TIME');
        return Db::table(static::$table)->insert($data);
    }

    public static function getNextId(){
        $data = Db::table(self::$table)
            ->field('nvl(max(LOG_ID),0) as NUM')
            ->find();
        if(empty($data) || !isset($data['NUM'])){
            return 1;
        }
        return $data['NUM'] + 1;
    }
}